<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div class="app">
        <h3>今天天气{{info}}</h3>
        <button @click="changeWeather">切换天气</button>
        <br>
        <h2>{{number.a}}</h2>
        <button @click="number.a++">点我a+1</button>
        <h2>{{number.b}}</h2>
        <button @click="number.b++">点我b+1</button>
    </div>
    <script>
        const vm = new Vue({
            data: {
                isHot: true,
                number: {
                    a: 1,
                    b: 1
                }
            },
            computed: {
                info() {
                    return this.isHot ? '热' : '也就那样'
                }
            },
            methods: {
                changeWeather() {
                    this.isHot = !this.isHot
                }
            },
            watch: {
                info: {
                    immediate: true, //初始化时让handler调用
                    handler(newValue, oldValue) {
                        console.log('info变化了', newValue, oldValue)
                    }
                },
                'number.a': {
                    handler(newValue, oldValue) {
                        console.log('a变化了', newValue, oldValue)
                    }
                },
                //深度监视 监视所有属性的变化
                number: {
                    deep: 1,
                    handler(newValue, oldValue) {
                        console.log('number变化了', newValue, oldValue)
                    }
                }
            }
        })
        vm.$mount('.app')
    </script>
</body>

</html>